/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgSkill
    {
        private readonly Dictionary<int, CfgSkill> _dataMap;
        private readonly List<CfgSkill> _dataList;


        public TbCfgSkill(ByteBuf _buf)
        {
            //first read common data
            _TbCommonSkill _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonSkill(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgSkill>(size * 3 / 2);
            _dataList = new List<CfgSkill>(size);

            for (int i = 0; i < size; i++)
            {
                CfgSkill _v;
                _v = CfgSkill.DeserializeCfgSkill(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgSkill> DataMap => _dataMap;
        public IReadOnlyList<CfgSkill> DataList => _dataList;

        public CfgSkill Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgSkill] config not found,id:" + key.ToString());

            return null;
        }

        public CfgSkill GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "skill";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgSkill LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgSkill(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgSkill
    {
        private CfgSkill(ByteBuf _buf, _TbCommonSkill _commonData)
        {
            Id = _buf.ReadInt();
            Name = TableCenter.GetI18NText(_buf.ReadInt());
            UnlockHeroLevel = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; Icon = _commonData._field0[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; SkillTag = _commonData._field1[dataIndex]; }
            SkillType = _buf.ReadInt();
            SkillSlot = _buf.ReadInt();
            SkillSlotPriiority = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; ResFloder = _commonData._field2[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; HitEffect = _commonData._field3[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; AISelectType = _commonData._field4[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; ResName = _commonData._field5[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; Indicator = _commonData._field6[dataIndex]; }
            IsLockTarget = _buf.ReadBool();
            InitialCoolDown = _buf.ReadInt();
            CoolDown = _buf.ReadInt();
            MaxRoundCount = _buf.ReadInt();
            BattleSkillCount = _buf.ReadInt();
            MaxTurnCount = _buf.ReadInt();
            MaxSkillCount = _buf.ReadInt();
            DamageType = _buf.ReadInt();
            WeaknessHit = _buf.ReadInt();
            SPCost = _buf.ReadInt();
            CostLimit = _buf.ReadInt();
            CameraType = _buf.ReadInt();

            PostInit();
        }

        internal static CfgSkill DeserializeCfgSkill(ByteBuf _buf, _TbCommonSkill _commonData)
        {
            return new CfgSkill(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 技能名称
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 解锁所需英雄等级
        /// </summary>
        public int UnlockHeroLevel { get; private set; }
        /// <summary>
        /// 图标(Assets\Res\05_Images\Sprite\Icon_Skill)
        /// </summary>
        public string Icon { get; private set; }
        /// <summary>
        /// 技能tag
        /// </summary>
        public IReadOnlyList<int> SkillTag { get; private set; }
        /// <summary>
        /// 技能类型1普攻 2技能 3奥义 4被动 5宠物技能
        /// </summary>
        public int SkillType { get; private set; }
        /// <summary>
        /// 角色技能槽位位置
        /// </summary>
        public int SkillSlot { get; private set; }
        /// <summary>
        /// 技能槽位优先级-数字大优先
        /// </summary>
        public int SkillSlotPriiority { get; private set; }
        /// <summary>
        /// 配置文件夹
        /// </summary>
        public string ResFloder { get; private set; }
        /// <summary>
        /// 受击特效
        /// </summary>
        public string HitEffect { get; private set; }
        /// <summary>
        /// 目标自动选择（公式ID|公式ID，优先前位）
        /// </summary>
        public IReadOnlyList<int> AISelectType { get; private set; }
        /// <summary>
        /// 配置
        /// </summary>
        public string ResName { get; private set; }
        /// <summary>
        /// 指示器预制体
        /// </summary>
        public string Indicator { get; private set; }
        /// <summary>
        /// 是否强制选目标（0不强制1强制）
        /// </summary>
        public bool IsLockTarget { get; private set; }
        /// <summary>
        /// 技能初始冷却
        /// </summary>
        public int InitialCoolDown { get; private set; }
        /// <summary>
        /// 技能冷却
        /// </summary>
        public int CoolDown { get; private set; }
        /// <summary>
        /// 每回合最多触发次数
        /// </summary>
        public int MaxRoundCount { get; private set; }
        /// <summary>
        /// 每场战斗最多使用次数
        /// </summary>
        public int BattleSkillCount { get; private set; }
        /// <summary>
        /// 每行动最多触发次数
        /// </summary>
        public int MaxTurnCount { get; private set; }
        /// <summary>
        /// 每个part最多触发次数
        /// </summary>
        public int MaxSkillCount { get; private set; }
        /// <summary>
        /// 伤害类型 1物理 2魔法 3冰 4火 5电
        /// </summary>
        public int DamageType { get; private set; }
        /// <summary>
        /// 弱点击破
        /// </summary>
        public int WeaknessHit { get; private set; }
        /// <summary>
        /// 技能消耗
        /// </summary>
        public int SPCost { get; private set; }
        /// <summary>
        /// 释放限制（用公式）
        /// </summary>
        public int CostLimit { get; private set; }
        /// <summary>
        /// 镜头类型0默认1中距离2远距离
        /// </summary>
        public int CameraType { get; private set; }

        /// <summary>
        /// Icon 资源全路径
        /// </summary>
        public string Icon_fullPath => $"Res/05_Images/Sprite/Icon_Skill/{Icon}";

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonSkill
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field1 { get; private set; }
        internal IReadOnlyList<string> _field2 { get; private set; }
        internal IReadOnlyList<string> _field3 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field4 { get; private set; }
        internal IReadOnlyList<string> _field5 { get; private set; }
        internal IReadOnlyList<string> _field6 { get; private set; }
        internal _TbCommonSkill(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field4 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field5 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field6 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
